package teleware.soe.core.strategy.impl;

import teleware.soe.core.annotation.ResourceMapping;
import teleware.soe.core.dto.MappingPool;
import teleware.soe.core.dto.MethodMapping;
import teleware.soe.core.enums.MappingEnum;
import teleware.soe.core.strategy.MappingStrategy;

import java.lang.reflect.Method;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 资源请求映射策略
 *
 * @author :hongsw
 * @date :2020-12-11 16:08
 */
public class ResourceMappingStrategy implements MappingStrategy {

    /**
     * 将方法存入映射池
     *
     * @param mappingEnum 注解枚举
     * @param method      方法
     * @param mappingPool 映射池
     * @author hongsw
     * @date 2020/12/11 17:07
     **/
    @Override
    public void process(MappingEnum mappingEnum, Method method, MappingPool mappingPool) {
        ResourceMapping resourceMapping = (ResourceMapping) method.getAnnotation(mappingEnum.getAnnotationClass());
        MethodMapping methodMapping = new MethodMapping();
        methodMapping.setMethod(method);
        methodMapping.setBeanName(method.getDeclaringClass().getName());
        ConcurrentHashMap<String, MethodMapping> resourceMappingPool = mappingPool.getResourceMappingPool();
        resourceMappingPool.put(resourceMapping.value(), methodMapping);
    }
}
